﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using System.Collections;
using System.Threading;
using System.Windows.Threading;
using System.Runtime.InteropServices;


[StructLayout(LayoutKind.Sequential)]
public struct SYSTEMTIME
{
    public short Year;
    public short Month;
    public short DayOfWeek;
    public short Day;
    public short Hour;
    public short Minute;
    public short Second;
    public short Milliseconds;
}



namespace GUI_CLock
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// 
    /// Clock code James Brooks/Dustin Phillips CST238 GUI Systems - Sherwin OIT  May 10, 2011
    /// This is a clock with analog, binary and digital views based on the Model View Controller pattern.
    /// </summary>
    public partial class MainWindow : Window
    {

        //This is the clock controller code.  It displays the main window with button controls for the
        //various clock displays including analog, digital and binary as well as controls for setting
        //the time.
        //
        //By default the clocks start with the system time.

        public MainWindow()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, RoutedEventArgs e)
        {
            // Show the Digital Clock
            Window1 dcwindow = new Window1();

            TimeModel tm = TimeModel.Instance;
            DigitalClock dclock = new DigitalClock(tm, dcwindow.canvas1 );

            dcwindow.Show();
            
        }

        private void button2_Click(object sender, RoutedEventArgs e)
        {
            //Show the binary clock
            Window2 bcwindow = new Window2();

            TimeModel tm = TimeModel.Instance;
            BinaryClock bclock = new BinaryClock(tm, bcwindow.canvas1);

            bcwindow.Show();

        }

        private void button3_Click(object sender, RoutedEventArgs e)
        {
            //Show the analog clock
            Window3 acwindow = new Window3();

            TimeModel tm = TimeModel.Instance;

            AnalogClockFace analogClock = new AnalogClockFace(tm, acwindow.canvas1);

            acwindow.Show();
        }

        private void button4_Click(object sender, RoutedEventArgs e)
        {
            //Capture the user input for time settings and adjust the time model
            int hour, minute, second;
            string tempstr;

            ComboBoxItem curItem = ((ComboBoxItem)comboBox1.SelectedItem);
            hour = Convert.ToInt32((string)curItem.Content);
            ComboBoxItem curItem2 = ((ComboBoxItem)comboBox2.SelectedItem);
            minute = Convert.ToInt32((string)curItem2.Content);
            ComboBoxItem curItem3 = ((ComboBoxItem)comboBox3.SelectedItem);
            second = Convert.ToInt32((string)curItem3.Content);
            ComboBoxItem curItem4 = ((ComboBoxItem)comboBox4.SelectedItem);
            tempstr = (string)curItem4.Content; 
            if (tempstr == "pm")
            { 
                hour = hour + 12;
                if (hour > 23)
                {
                    hour = 12;
                }
            }
            
            TimeModel tm = TimeModel.Instance;
            tm.AdjustTime(hour, minute, second);

        }
    } 
}
